#pragma once

#include "ZNetworkCommon.h"
#include <boost/thread.hpp>
#include <boost/shared_ptr.hpp>

namespace	Z	{

//------------------------------------------------------------------------------------------------------------------------
class	SocketNetworkController;
class	Socket;

class	_ZNetworkApi	Acceptor
{
public:
	Acceptor(SocketNetworkController* pSocketNetworkController, u_short port);
	~Acceptor();
	bool	start();
	void	destroy();
	void	accept();
	void	process();
private:
	bool	create();
	bool	bind(u_short port);
	bool	selectEvent();
	bool	startProcess();
	bool	listen();

private:
	u_short	mPort;
	SocketNetworkController*		mSocketNetworkController;
	boost::thread	mProcessThread;
	WSAEVENT	mProcess;
	WSAEVENT	mAccept;
	typedef	boost::shared_ptr<Socket>	SocketPtr;
	SocketPtr	mSocket;
};

}